package com.cby.util.lib.util

import android.text.TextUtils
import android.util.Log

/**
 * @description: CbyLogUtils
 *
 * @author ChenBaoYang
 * @date 6/1/21 10:26
 */
object CbyLogUtils {

    var isDebug = false

    private const val PREFIX_TAG = "CbyLogUtils-"
    private const val DEFAULT_TAG = "Cby"
    private const val LOG_MSG_PREFIX = "log start --> "
    private const val LOG_MSG_SUFFIX = "<-- log end "
    private const val LOG_SEPARATOR = " - "

    fun i(tag: String, msg: String?) {
        if (isDebug && !TextUtils.isEmpty(msg)) {
            Log.i(PREFIX_TAG + tag, msg!!)
        }
    }

    fun e(tag: String, msg: String?) {
        if (isDebug && !TextUtils.isEmpty(msg)) {
            Log.e(PREFIX_TAG + tag, msg!!)
        }
    }

    /**
     * 强制性的日志输出，用于在游戏接入，查看排查
     */
    fun flog(vararg messages: String?) {
        val msgBuilder = StringBuilder(LOG_MSG_PREFIX)
        for (i in messages.indices) {
            msgBuilder.append(messages[i])
            if (i == messages.size - 1) {
                break
            }
            msgBuilder.append(LOG_SEPARATOR)
        }
        msgBuilder.append(LOG_MSG_SUFFIX)
        Log.i(DEFAULT_TAG, msgBuilder.toString())
    }

}